home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / WASTE 1.2a4 / WASTE Demo / WEDemoIntf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-05  |  2.3 KB  |  124 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     Utility Functions
  4.     
  5.     Copyright © 1993-1995 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     In Pascal, an "intf" file is sorta like a .h (header) file in C:  it contains a lot
  13.     of the declarations and definitions of things used in general by the entirity of
  14.     the code.
  15.     
  16.     Most of the code from the WEDemoIntf.p file has been placed into the WEDemoHeader.h
  17.     file except for some general purpose utility functions, which have then been
  18.     placed here.
  19. */
  20.  
  21. #ifndef    __WEDEMOAPP__
  22. #include "WEDemoIntf.h"
  23. #endif
  24.  
  25. Boolean        gHasColorQD = false;
  26. Boolean        gHasDragAndDrop = false;
  27. Boolean        gHasTextServices = false;
  28. Boolean        gExiting = false;
  29.  
  30.  
  31. DocumentHandle    GetWindowDocument( WindowRef window )
  32. {
  33.     // make sure window is not NULL and is one of our windows
  34.     if (( window == NULL ) || ( GetWindowKind( window ) != userKind ))
  35.         return NULL;
  36.     
  37.     // a handle to the document structure is kept in the window refCon
  38.     return (DocumentHandle) GetWRefCon( window );
  39. }
  40.  
  41. void    ErrorAlert( OSErr err )
  42. {
  43.     Str255        errString;
  44.     short        alertResult;
  45.     
  46.     NumToString( err, errString );
  47.     ParamText( errString, "\p", "\p", "\p" );
  48.     
  49.     SetCursor( &qd.arrow );
  50.     
  51.     alertResult = Alert( kAlertGenError, GetMyStandardDialogFilter() );
  52.     
  53.     return;
  54. }
  55.  
  56.  
  57. void    ForgetHandle( Handle *h )
  58. {
  59.     Handle        theHandle;
  60.     
  61.     theHandle = *h;
  62.     
  63.     if ( theHandle != NULL )
  64.     {
  65.         *h = NULL;
  66.         DisposeHandle( theHandle );
  67.     }
  68.     
  69.     return;
  70. }
  71.  
  72. void    ForgetResource( Handle *h )
  73. {
  74.     Handle        theHandle;
  75.     
  76.     theHandle = *h;
  77.     
  78.     if ( theHandle != NULL )
  79.     {
  80.         *h = NULL;
  81.         ReleaseResource( theHandle );
  82.     }
  83.     
  84.     return;
  85. }
  86.  
  87. OSErr    NewHandleTemp( Size blockSize, Handle *h )
  88. {
  89.     OSErr        err;
  90.     
  91.     // allocate a new relocatable block from temporary memory, or
  92.     // if that fails, from the current heap
  93.     
  94.     // first try tapping temporary memory
  95.     
  96.     *h = TempNewHandle( blockSize, &err );
  97.     
  98.     // in case of failure, try with current heap
  99.     
  100.     if ( *h == NULL )
  101.     {
  102.         *h = NewHandle( blockSize );
  103.         err = MemError();
  104.     }
  105.     
  106.     return err;
  107. }
  108.  
  109. // this is a function not originally in the WASTE Demo App, however due to the
  110. // differences between Pascal and C, it's necessary to have to accomplish things.
  111.  
  112. void    PStringCopy( ConstStr255Param srcString, Str255 destString )
  113. {
  114.     register short    index;
  115.     
  116.     index = srcString[0] + 1;
  117.     
  118.     while( index-- )
  119.     {
  120.         *destString++ = *srcString++;
  121.     }
  122.     
  123.     return;
  124. }